package com.ahpome.util;

import java.text.DecimalFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.logging.SimpleFormatter;

public class FormatTool {
	
	/*******************ʱ���ʽת��**************************/
	private static SimpleDateFormat sd1=new SimpleDateFormat("yyyy-MM-dd");
	private static SimpleDateFormat sd2=new SimpleDateFormat("yyyy-MM-dd HH:ss:mm");
	private static SimpleDateFormat sd3=new SimpleDateFormat("yyyy年MM月dd日HH时ss分");
	private static SimpleDateFormat sm = new SimpleDateFormat("yyMMddHHmmssSS");
	/*******************���ָ�ʽת��**************************/
	private static DecimalFormat df=new DecimalFormat("#.00"); 
	/*******************�ַ��ʽת��**************************/
	private static SimpleFormatter sf=new SimpleFormatter();
	/**
	 * ���id�뵱ǰʱ�����һ���ַ�
	 * @param id
	 * @return
	 */
	public static String getSeq(Integer id){
		StringBuilder seq = new StringBuilder(sm.format(new Date())+ new DecimalFormat("000").format(id));
		return seq.toString();
	}
	/**
	 * ��ʽ��ʱ��  yyyy-MM-dd
	 * @param date
	 * @return
	 */
	public static String getDateOne(Date date){
		return sd1.format(date);
	}
	/**
	 * ��ʽ��ʱ��  yyyy-MM-dd hh:ss:mm
	 * @param date
	 * @return
	 */
	public static String getDateTwo(Date date){
		return sd2.format(date);
	}
	/**
	 * ��ʽ��double
	 * @param price
	 * @return
	 */
	public static Double getPrice(Double price){
		return Double.valueOf(df.format(price));
	}
	/**
	 * �����ַ��ض�λ�õ��ַ�
	 * @param str
	 * @param start>0
	 * @param end
	 * @return
	 */
	public static String getHide(String str,int start,int end){
		char[] cs=str.toCharArray();
		for (int i=start;i<=end;i++) {
			cs[i]='*';
		}
		return String.valueOf(cs);
	}
	/**
	 * ���n���ڵ������
	 * @param n
	 * @return
	 */
	public static Integer getNum(int n){
		Random random=new Random();		
		return random.nextInt(n);
	}
	/**
	 * ���start-end�ڵ������
	 * @param start
	 * @param end
	 * @return
	 */
	public static Integer getBetweenNum(int start,int end){
		Random random=new Random();	
		Boolean flag=true;
		Integer num=0;
		while(flag){
			if(end<start){
				num=random.nextInt(start+1);
				if(num>(end-1)&&num<(start+1)){
					flag=false;
				}
			}else if(end==start){
				num=end;
				flag=false;
			}else{
				num=random.nextInt(end+1);
				if(num>(start-1)&&num<(end+1)){
					flag=false;
				}
			}			
		}
		return num;
	}
	/**
	 * 生成文件名称
	 * @param ext 后缀
	 * @return
	 */
	public static String fileName(String ext){
		SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMddhhmmssss");
		String fileName=sdf.format( new Date()) ;
		if(ext!=null&&!"".equals(ext)){
			 fileName = fileName+ "." + ext;
			return  fileName;
		}else{
			return fileName;
		}
	}
	public static String getNowDay(){
		System.out.println(sd3.format(new Date()));
		return sd3.format(new Date());
	}
	public static void main(String[] args) {
		getNowDay();
	}
}
